package opeartion;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        Scanner in=new Scanner(System.in);
        System.out.println("新增图书!");
        System.out.println("请输入图书的名字：");
        String name=in.nextLine();
        System.out.println("请输入图书的作者：");
        String author=in.nextLine();
        System.out.println("请输入图书的类型：");
        String type=in.nextLine();
        System.out.println("请输入图书的价格：");
        int price= in.nextInt();
        Book book=new Book(name,author,price,type);
        int size=bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book book1=bookList.getBooks(i);
            if (book1.getName().equals(name)){
                System.out.println("已经存在这本书了！");
                return;
            }
        }
        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);
        System.out.println("新增图书成功！");
    }
}
